/*
 * @Author: your name
 * @Date: 2021-09-02 11:32:45
 * @LastEditTime: 2021-09-02 15:30:18
 * @LastEditors: Please set LastEditors
 * @Description: 师范
 * @FilePath: \uniapp-cil\src\store\book.js
 */

const book = {
    // 命名空间
    namespaced: true,
    state: {
        name: "",
        price: ""
    },
    mutations: {
        setBookName(state, obj) {
            state.name = obj
        },
        setBookPrice(state, obj) {
            state.price = obj
        }
    },
    actions: {
        setBookName: {
            root: true,
            handler({ commit, state }, obj) {
                setTimeout(() => {
                    commit('setBookName', obj)
                    console.log(state, "数的名称");
                }, 1000)
            }
        },


        async setBookPrice({ dispatch, commit, state }, obj) {
            // 在子模块中使用全局的action方法
            let res = await dispatch('getPrice', null, { root: true })
                // 在组件中使用子模块的方法
                // this.$store.dispatch('book/setBookPrice',null)

            commit('setBookPrice', res)
            console.log(state, "书的商品价格", res);
        },
    }
}
export default book